import 'dart:convert';

import 'package:crypto/crypto.dart';
import 'package:wu_you/utils/utils.dart';

class SignUtil {
  ///加密
  static String sign(Map<String, dynamic> param) {
    var sortedKeys = param.keys.toList()..sort();
    StringBuffer sb = StringBuffer();
    sortedKeys.forEach((element) {
      sb..write(element)..write("=")..write(param[element])..write("&");
    });
    String signText = sb.toString().substring(0, sb.length - 1);
    return md5.convert(utf8.encode(signText)).toString();
  }

  ///加密设备信息
  static Future<String> signByDeviceInfo() async {
    return sign(await Utils.getDeviceInfo());
  }
}
